﻿using DevComponents.DotNetBar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WorkStation.Common;

namespace WorkStation.UI
{
    public partial class FormAddModule : Office2007Form
    {
        private List<string> _names;
        private string _reviseName;
        public string ModuleName { get; set; }
        public FormAddModule(List<string> names, string reviseName = "")
        {
            InitializeComponent();
            _names = names;
            this.EnableGlass = false;
            this._reviseName = reviseName;
        }

        private void btn_Confirm_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tB_ModuleName.Text))
            {
                SystemInfo.ShowToastInfo(this, "模组名称不能为空!", true);
                return;
            }
            if(_names != null && _names.Count > 0)
            {
                if(_names.Contains(tB_ModuleName.Text))
                {
                    SystemInfo.ShowToastInfo(this, "已存在同名模组!", true);
                    return;
                }
            }
            this.ModuleName = tB_ModuleName.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void FormAddModule_Load(object sender, EventArgs e)
        {
            if(!string.IsNullOrEmpty(_reviseName))
            {
                this.tB_ModuleName.Text = _reviseName;
            }
        }
    }
}
